package com.gin.no_gay_alliance.adpter.forum;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;

import com.gin.nga.enums.SubForumType;
import com.gin.no_gay_alliance.adpter.base.BaseBindingRecyclerViewAdapter;
import com.gin.no_gay_alliance.customview.ForumEntryView;
import com.gin.no_gay_alliance.databinding.ItemForumSearchResultBinding;
import com.gin.no_gay_alliance.viewmodel.ForumSearchResult;

import java.util.List;

/**
 * 版面搜索结果
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/31 15:20
 **/
public class ForumSearchResultAdapter extends BaseBindingRecyclerViewAdapter<ItemForumSearchResultBinding, ForumSearchResult> {
    public ForumSearchResultAdapter(Context context) {
        super(context);
    }

    public ForumSearchResultAdapter(@NonNull Context context, @NonNull List<ForumSearchResult> data) {
        super(context, data);
    }

    @Override
    protected void onBindViewHolder(ViewHolder<ItemForumSearchResultBinding> holder, @NonNull ItemForumSearchResultBinding b, int position, ForumSearchResult item) {
        ForumEntryView result = b.fevResult;
        ForumEntryView parent = b.fevParent;

        result.init(item, 0, 64);

        if (item.parentId != null) {
            parent.setVisibility(View.VISIBLE);
            parent.init(item.parentName, 2, 48, item.parentIcon, SubForumType.FORUM, item.parentId);
        } else {
            parent.setVisibility(View.GONE);
        }
    }

    @NonNull
    @Override
    protected ItemForumSearchResultBinding buildBinding(LayoutInflater inflater) {
        return ItemForumSearchResultBinding.inflate(inflater);
    }
}
